
#ifndef CHARTVIEW_H
#define CHARTVIEW_H

#pragma warning(disable:4251)

#include <BMap>
#include <BFont>
#include <BIcon>
#include <BPointArray>
#include <BScrollArea>
#include <BRange>

#include "Series.h"

class ChartView : public BScrollArea
{
	BOBJECT(ChartView)
public:
	ChartView(BWidget* parent = 0);
	ChartView(const BString& title, BWidget* parent = 0);
	~ChartView();

	void setVerticalLabel(const BString& verticalLabel);
	const BString& verticalLabel() const;
	const BRect& valueLabelRect() const;

	void setHorizontalLabel(const BString& horizontalLabel);
	const BString& horizontalLabel() const;

	void setValueColor(const BColor& color);
	const BColor& valueColor() const;

	void setValueScale(BReal valueScale);
	BReal valueScale() const;

	void setValueUnit(BReal valueUnit);
	BReal valueUnit() const;

	void setValueDecimals(int decimals);
	int valueDecimals() const;

	void setValueRange(BReal minValue, BReal maxValue);
	void setValueRange(const BRealRange& valueRange);
	const BRealRange& valueRange() const;

	void setTimeColor(const BColor& color);
	const BColor& timeColor() const;

	void setTimeScale(BReal timeScale);
	BReal timeScale() const;

	void setTimeUnit(BReal timeUnit);
	BReal timeUnit() const;

	void setTimeRange(BReal minTime, BReal maxTime);
	void setTimeRange(const BRealRange& timeRagne);
	const BRealRange& timeRange() const;

	void setWheelStep(BReal wheelStep);
	BReal wheelStep() const;

	bool addSeries(Series* series);
	Series* addSeries(const BString& name);
	bool removeSeries(Series* series);
	bool removeSeries(const BString& name);

	void clearSeries();
	int seriesIndex(Series* series);

	int seriesCount() const;
	Series* series(int index);
	Series* namedSeries(const char* name);
	Series* namedSeries(const BString& name);

	void fullView(Orientation orientation = Orientation_Crossing);
	bool freshRanges();
	void hintValueUnit();
	void hintTimeUnit();

	virtual BSize sizeHint() const;

protected:
	void initialize();
	const BRealPointArray& seriesLines(int index);

protected:
	void slotSeriesVisibleChanged();
	void slotSeriesChanged();

protected:
	virtual void scrolling(Orientation orientation);

protected:
	virtual void resizeEvent(const BEvent& event);

	virtual void styleEvent(const BEvent& event);
	virtual void freshEvent(const BEvent& event);
	virtual void paintEvent(const BEvent& event);

	virtual void mouseEnterEvent(const BMouseEvent& mouseEvent);
	virtual void mouseLeaveEvent(const BMouseEvent& mouseEvent);

	virtual void mousePressEvent(const BMouseEvent& mouseEvent);
	virtual void mouseReleaseEvent(const BMouseEvent& mouseEvent);

	virtual void mouseMoveEvent(const BMouseEvent& mouseEvent);
	virtual void mouseClickEvent(const BMouseEvent& mouseEvent);
	virtual void mouseWheelEvent(const BMouseEvent& mouseEvent);

private:
	int					_frequency;
	BReal				_wheelStep;
	BReal				_valueScale;
	BReal				_timeScale;
	BReal				_valueUnit;
	int					_valueDecimals;
	BReal				_timeUnit;
	BFontHolder			_numberFont;
	BString				_verticalLabel;
	BString				_horizontalLabel;
	bool				_middlePressed;
	BPoint				_pressedPoint;
	BRect				_pressedArea;

	bool				_dirty;
	BRealRange			_valueRange;
	BRealRange			_timeRange;

	BColor				_horRuleColor;
	BRect				_horRulerRect;
	BRect				_horLabelRect;
	BPoint				_horRulerTriangle[3];

	BColor				_verRuleColor;
	BRect				_verRulerRect;
	BRect				_verLabelArea;
	BRect				_valueLabelRect;
	BPoint				_verRulerTriangle[3];

	bool					_dirtyLines;
	BArray<BRealPointArray>	_lineArraies;
	BRealPointArray			_horPoints;
	BRealPointArray			_verPoints;
	BArray<SeriesHolder>	_seriesArray;


	bool				_pressState;
	BPoint				_pressPoint;
	BPoint				_releasePoint;
};

#endif
